﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EFong.ServicesInterface;
using EFong.BL;

namespace EFong.Services
{
    public class MasterService : IMasterService, IService
    {
        #region IMasterService 成员

        public Contract.ServiceResult<List<Contract.Project>> GetAllProject()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.Project>>(masterBL.GetAllProject());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.Project>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.Project>>(e); }
        }

        public Contract.ServiceResult<List<Contract.Project>> GetAllOtherProject()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.Project>>(masterBL.GetAllOtherProject());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.Project>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.Project>>(e); }
        }

        public Contract.ServiceResult NewProject(Contract.Project project)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                masterBL.NewProject(project);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult UpdateProject(Contract.Project project)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                masterBL.UpdateProject(project);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult UpdateProjectList(List<Contract.Project> projectList)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                masterBL.UpdateProjectList(projectList);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult<List<Contract.BankAccount>> GetAllBankAccount()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.BankAccount>>(masterBL.GetAllBankAccount());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.BankAccount>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.BankAccount>>(e); }
        }

        public Contract.ServiceResult NewBankAccount(Contract.BankAccount bankAccount)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                masterBL.NewBankAccount(bankAccount);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult UpdateBankAccounts(List<Contract.BankAccount> bankAccounts)
        {
            foreach (var eachBankAccount in bankAccounts)
            {
                Contract.ServiceResult r = UpdateBankAccount(eachBankAccount);
                if (!r.IsSuccess) return r;
            }
            return this.Return();
        }

        public Contract.ServiceResult UpdateBankAccount(Contract.BankAccount bankAccount)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                masterBL.UpdateBankAccount(bankAccount);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult<List<Contract.RCustomer>> GetAllCustomer()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.RCustomer>>(masterBL.GetAllCustomer());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.RCustomer>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.RCustomer>>(e); }
        }

        public Contract.ServiceResult<List<Contract.RCustomer>> GetCustomerByName(string name)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.RCustomer>>(masterBL.GetCustomerByName(name));
            }
            catch (BusinessException be) { return this.Fail<List<Contract.RCustomer>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.RCustomer>>(e); }
        }

        public Contract.ServiceResult<List<Contract.RCustomer>> GetCustomerByAddress(string address)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.RCustomer>>(masterBL.GetCustomerByAddress(address));
            }
            catch (BusinessException be) { return this.Fail<List<Contract.RCustomer>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.RCustomer>>(e); }
        }

        public Contract.ServiceResult<List<Contract.RCustomer>> GetCustomerByTel(string tel)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.RCustomer>>(masterBL.GetCustomerByTel(tel));
            }
            catch (BusinessException be) { return this.Fail<List<Contract.RCustomer>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.RCustomer>>(e); }
        }

        public Contract.ServiceResult<List<Contract.RCustomer>> GetCustomerBySalesman(Contract.User salesman)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.RCustomer>>(masterBL.GetCustomerBySalesman(salesman));
            }
            catch (BusinessException be) { return this.Fail<List<Contract.RCustomer>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.RCustomer>>(e); }
        }

        public Contract.ServiceResult<Contract.Customer> GetCustomerByID(Guid id)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<Contract.Customer>(masterBL.GetCustomerByID(id));
            }
            catch (BusinessException be) { return this.Fail<Contract.Customer>(be); }
            catch (Exception e) { return this.Fail<Contract.Customer>(e); }
        }

        public Contract.ServiceResult<string> NewCustomer(Contract.Customer customer)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<string>(masterBL.NewCustomer(customer));
            }
            catch (BusinessException be) { return this.Fail<string>(be); }
            catch (Exception e) { return this.Fail<string>(e); }
        }

        public Contract.ServiceResult UpdateCustomer(Contract.Customer customner)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                masterBL.UpdateCustomer(customner);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult DeleteCustomer(Contract.Customer customner)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                masterBL.DeleteCustomer(customner);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult<List<Contract.RVendor>> GetAllVendor()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.RVendor>>(masterBL.GetAllVendor());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.RVendor>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.RVendor>>(e); }
        }

        public Contract.ServiceResult<List<Contract.RVendor>> GetAllHotelVendor()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.RVendor>>(masterBL.GetAllHotelVendor());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.RVendor>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.RVendor>>(e); }
        }

        public Contract.ServiceResult<List<Contract.RVendor>> GetAllTrainVendor()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.RVendor>>(masterBL.GetAllTrainVendor());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.RVendor>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.RVendor>>(e); }
        }

        public Contract.ServiceResult<List<Contract.RVendor>> GetAllFlightVendor()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.RVendor>>(masterBL.GetAllFlightVendor());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.RVendor>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.RVendor>>(e); }
        }

        public Contract.ServiceResult<List<Contract.RVendor>> GetAllInsuranceVendor()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.RVendor>>(masterBL.GetAllInsuranceVendor());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.RVendor>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.RVendor>>(e); }
        }

        public Contract.ServiceResult<Contract.Vendor> GetVendorByID(Guid id)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<Contract.Vendor>(masterBL.GetVendorByID(id));
            }
            catch (BusinessException be) { return this.Fail<Contract.Vendor>(be); }
            catch (Exception e) { return this.Fail<Contract.Vendor>(e); }
        }

        public Contract.ServiceResult<List<Contract.RVendor>> GetVendorByProject(Contract.Project project)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.RVendor>>(masterBL.GetVendorByProject(project));
            }
            catch (BusinessException be) { return this.Fail<List<Contract.RVendor>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.RVendor>>(e); }
        }

        public Contract.ServiceResult<string> NewVendor(Contract.Vendor vendor)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<string>(masterBL.NewVendor(vendor));
            }
            catch (BusinessException be) { return this.Fail<string>(be); }
            catch (Exception e) { return this.Fail<string>(e); }
        }

        public Contract.ServiceResult UpdateVendor(Contract.Vendor vendor)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                masterBL.UpdateVendor(vendor);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult<List<Contract.InsurancePolicy>> GetAllInsurancePolicy()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.InsurancePolicy>>(masterBL.GetAllInsurancePolicy());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.InsurancePolicy>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.InsurancePolicy>>(e); }
        }

        public Contract.ServiceResult<List<Contract.InsurancePolicy>> GetAllAvailableInsurancePolicy()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.InsurancePolicy>>(masterBL.GetAllAvailableInsurancePolicy());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.InsurancePolicy>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.InsurancePolicy>>(e); }
        }

        public Contract.ServiceResult NewInsurancePolicy(Contract.NewInsurancePolicy newInsurancePolicy)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                masterBL.NewInsurancePolicy(newInsurancePolicy);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult<Contract.InsurancePolicy> ReturnInsurancePolicy(Contract.InsurancePolicy oldInsurancePolicy, string newNr)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<Contract.InsurancePolicy>(masterBL.ReturnInsurancePolicy(oldInsurancePolicy, newNr));
            }
            catch (BusinessException be) { return this.Fail<Contract.InsurancePolicy>(be); }
            catch (Exception e) { return this.Fail<Contract.InsurancePolicy>(e); }
        }

        public Contract.ServiceResult UpdateInsurancePolicy(Contract.InsurancePolicy insurancePolicy)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                masterBL.UpdateInsurancePolicy(insurancePolicy);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult<Contract.InsurancePolicy> GetAvailableInsurancePolicy(Contract.RVendor vendor, string type)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<Contract.InsurancePolicy>(masterBL.GetAvailableInsurancePolicy(vendor, type));
            }
            catch (BusinessException be) { return this.Fail<Contract.InsurancePolicy>(be); }
            catch (Exception e) { return this.Fail<Contract.InsurancePolicy>(e); }
        }

        public Contract.ServiceResult<List<string>> GetInsurancePolicyTypeList()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<string>>(masterBL.GetInsurancePolicyTypeList());
            }
            catch (BusinessException be) { return this.Fail<List<string>>(be); }
            catch (Exception e) { return this.Fail<List<string>>(e); }
        }

        public Contract.ServiceResult<List<Contract.JourneyOrder>> GetAllJourneyOrder()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.JourneyOrder>>(masterBL.GetAllJourneyOrder());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.JourneyOrder>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.JourneyOrder>>(e); }
        }

        public Contract.ServiceResult<List<Contract.JourneyOrder>> GetAllAvailableJourneyOrder()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.JourneyOrder>>(masterBL.GetAllAvailableJourneyOrder());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.JourneyOrder>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.JourneyOrder>>(e); }
        }

        public Contract.ServiceResult NewJourneyOrder(List<Contract.JourneyOrder> journeyOrderList)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                masterBL.NewJourneyOrder(journeyOrderList);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult UpdateJourneyOrder(Contract.JourneyOrder journeyOrder)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                masterBL.UpdateJourneyOrder(journeyOrder);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult<Contract.JourneyOrder> ReturnJourneyOrder(Contract.JourneyOrder oldJourneyOrder, string newNr)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<Contract.JourneyOrder>(masterBL.ReturnJourneyOrder(oldJourneyOrder, newNr));
            }
            catch (BusinessException be) { return this.Fail<Contract.JourneyOrder>(be); }
            catch (Exception e) { return this.Fail<Contract.JourneyOrder>(e); }
        }

        public Contract.ServiceResult<Contract.JourneyOrder> GetAvailableJourneyOrder(string type)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<Contract.JourneyOrder>(masterBL.GetAvailableJourneyOrder(type));
            }
            catch (BusinessException be) { return this.Fail<Contract.JourneyOrder>(be); }
            catch (Exception e) { return this.Fail<Contract.JourneyOrder>(e); }
        }

        public Contract.ServiceResult<List<string>> GetJourneyOrderTypeList()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<string>>(masterBL.GetJourneyOrderTypeList());
            }
            catch (BusinessException be) { return this.Fail<List<string>>(be); }
            catch (Exception e) { return this.Fail<List<string>>(e); }
        }

        public Contract.ServiceResult UpdateTourVendor(Contract.TourVendor tourVendor)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                masterBL.UpdateTourVendor(tourVendor);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult<List<Contract.RTourVendor>> GetAllTourVendor()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.RTourVendor>>(masterBL.GetAllTourVendor());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.RTourVendor>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.RTourVendor>>(e); }
        }

        public Contract.ServiceResult<List<Contract.RVendor>> GetAllTourpartyVendor()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.RVendor>>(masterBL.GetAllTourpartyVendor());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.RVendor>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.RVendor>>(e); }
        }

        public Contract.ServiceResult<Contract.TourVendor> GetTourVendorByID(Guid id)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<Contract.TourVendor>(masterBL.GetTourVendorByID(id));
            }
            catch (BusinessException be) { return this.Fail<Contract.TourVendor>(be); }
            catch (Exception e) { return this.Fail<Contract.TourVendor>(e); }
        }

        public Contract.ServiceResult<List<Contract.SearchTour>> GetTourByName(string name)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.SearchTour>>(masterBL.GetTourByName(name));
            }
            catch (BusinessException be) { return this.Fail<List<Contract.SearchTour>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.SearchTour>>(e); }
        }

        public Contract.ServiceResult<string> UpdateTouringParty(Contract.TouringParty touringParty)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<string>(masterBL.UpdateTouringParty(touringParty));
            }
            catch (BusinessException be) { return this.Fail<string>(be); }
            catch (Exception e) { return this.Fail<string>(e); }
        }

        public Contract.ServiceResult<List<Contract.RTouringParty>> GetAllTouringParty()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.RTouringParty>>(masterBL.GetAllTouringParty());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.RTouringParty>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.RTouringParty>>(e); }
        }

        public Contract.ServiceResult<Contract.TouringParty> GetTouringPartyByID(Guid id)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<Contract.TouringParty>(masterBL.GetTouringPartyByID(id));
            }
            catch (BusinessException be) { return this.Fail<Contract.TouringParty>(be); }
            catch (Exception e) { return this.Fail<Contract.TouringParty>(e); }
        }

        public Contract.ServiceResult VoidTouringParty(Contract.TouringParty touringParty, string cause)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                masterBL.VoidTouringParty(touringParty, cause);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        public Contract.ServiceResult<List<Contract.STour>> SearchTourByNameAndTravel(string name, string vendor, string type, string area, string feature, string travel)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.STour>>(masterBL.SearchTourByNameAndTravel(name, vendor,type,area,feature,travel));
            }
            catch (BusinessException be) { return this.Fail<List<Contract.STour>>(be); }
            catch (Exception e) { return this.Fail < List<Contract.STour >> (e); }
        }

        public Contract.ServiceResult<List<Contract.TourItemType>> GetTourItemTypeList()
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                return this.Return<List<Contract.TourItemType>>(masterBL.GetTourItemTypeList());
            }
            catch (BusinessException be) { return this.Fail<List<Contract.TourItemType>>(be); }
            catch (Exception e) { return this.Fail<List<Contract.TourItemType>>(e); }
        }

        public Contract.ServiceResult UpdateTourItemTypeList(List<Contract.TourItemType> list)
        {
            try
            {
                MasterBL masterBL = new MasterBL();
                masterBL.UpdateTourItemTypeList(list);
                return this.Return();
            }
            catch (BusinessException be) { return this.Fail(be); }
            catch (Exception e) { return this.Fail(e); }
        }

        #endregion
    }
}
